package com.cskaoyan.shopping.controller.lzh;


import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.shopping.dto.AllProductCateRequest;
import com.cskaoyan.shopping.dto.AllProductCateResponse;
import com.cskaoyan.shopping.service.IHomeService;
import com.cskaoyan.shopping.service.IProductCateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("shopping")
public class Shopping123Controller {

    @Autowired
    IHomeService iHomeService;


    @Autowired
    IProductCateService productCateService;


    // /shopping/homepage
    @GetMapping("homepage")
    public ResponseData homepage(){

        ResponseData responseData = new ResponseData();
        responseData.setResult(iHomeService.homepage().getPanelContentItemDtos());
        responseData.setSuccess(true);
        responseData.setCode(200);
        responseData.setMessage("success");
        return responseData;

    }

    // /shopping/navigation
    @GetMapping("navigation")
    public ResponseData navigation(){

        ResponseData responseData = new ResponseData();
        responseData.setResult(iHomeService.navigation());
        responseData.setSuccess(true);
        responseData.setCode(200);
        responseData.setMessage("success");
        return responseData;
    }

    // // /shopping/categories
    // @GetMapping("categories")
    // public ResponseData categories(){
    //
    //     ResponseData responseData = new ResponseData();
    //     responseData.setResult(iHomeService.categories());
    //     responseData.setSuccess(true);
    //     responseData.setCode(200);
    //     responseData.setMessage("success");
    //     return responseData;
    // }

    @RequestMapping("categories")
    public ResponseData categories(AllProductCateRequest request){

        AllProductCateResponse allProductCateResponse = productCateService.getAllProductCate(request);
        if (ShoppingRetCode.SUCCESS.getCode().equals(allProductCateResponse.getCode())){
            return new ResponseUtil().setData(allProductCateResponse.getProductCateDtoList());
        }

        return new ResponseUtil().setErrorMsg(allProductCateResponse.getMsg());

    }
}
